<style>
    .pane-form {
        min-height: calc(100vh - 165px);
    }
    /* 根据字数修改 */
    .layui-form-label {
        width: 100px;
        text-align: left;
    }

    .layui-mini {
        display: inline-block;
        width: 100px;
        height: 32px;
        border-radius: 4px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <!-- 用于创建子页面 -->
    <div class="page-create"></div>
    <!-- page-main-create -->
    <!-- 用于显示 隐藏 -->
    <div class="layuimini-main page-main-create">
        <div class="title-row layuimini-title title-sticky pb-0">
            <div class="title-left">
                <div class="layui-tabs noborder" id="planTabs">
                    <ul class="layui-tabs-header">
                        <li lay-closable="false">云城工单应用（APP端）</li>
                        <li lay-closable="false">平台侧工单配置（PC端）</li>
                        <li lay-closable="false">其他工单配置</li>
                    </ul>
                </div>
            </div>
            <div class="title-right">

            </div>
        </div>
        <div id="pane-0" class="pane-form layui-form" action="">
            <div class="section">
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">相机配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-on="on_camera">编辑</button>
                        </div>
                    </div>
                    <div class="p-4 layui-bg-gray mb-4">
                        <div class="pb-3">1、通用规则（含派单、做单）</div>
                        <div>水印相机：显示二维码</div>
                    </div>
                    <div class="p-4 layui-bg-gray mb-4">
                        <div class="pb-3">2、特殊规则（仅适用做单）</div>
                        <div class="pb-3">以下情况允许使用本地相机做单</div>
                        <div>工单来源：政府报事,市民报事</div>
                    </div>
                </div>
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">显示配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary"
                                lay-on="on_order_display">编辑</button>
                        </div>
                    </div>
                    <div class="p-4">报单人字段：显示</div>
                </div>


                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">工作组管理配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-on="on_work_group">编辑</button>
                        </div>
                    </div>
                    <div class="p-4">“云城工单”工作组入口权限：已开启</div>
                </div>
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">岗位报单配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary"
                                lay-on="on_job_requisition">添加</button>
                        </div>
                    </div>

                    <div class="p-4">
                        <div class="table-stripe">
                            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                        </div>
                    </div>
                    <script type="text/html" id="currentTableBar">
                        <a class="layui-font-blue mr-3" lay-event="edit">编辑</a>
                        <a class="layui-font-blue mr-3" lay-event="delete">删除</a>
                    </script>
                </div>
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">工作位置配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary"
                                lay-on="on_work_position">添加</button>
                        </div>
                    </div>

                    <p>以下位置在报单时隐藏，不用于工单派发</p>

                    <div class="p-4">
                        <div class="table-stripe">
                            <table class="layui-hide" id="jobTableId" lay-filter="currentTableFilter"></table>
                        </div>
                    </div>
                    <script type="text/html" id="currentTableBar">
                        <a class="layui-font-blue mr-3" lay-event="edit">编辑</a>
                        <a class="layui-font-blue mr-3" lay-event="delete">删除</a>
                    </script>
                </div>


                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">完工描述配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary"
                                lay-on="on_complete_description">编辑</button>
                        </div>
                    </div>
                    <div class="p-4">完工描述：已完成该项工作</div>
                </div>

            </div>
        </div>

        <div id="pane-1" class="pane-form layui-form layui-hide" action="">
            <div class="section">
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">视频报单配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-on="on_video_order">编辑</button>
                        </div>
                    </div>
                    <div class="p-4 layui-font-gray layui-font-12">
                        该配置仅生效于通过视频进行手动报单在派发工单时，是否同时生成时间进行跟踪
                    </div>
                    <div class="p-4">视频报单同时生成事件：关闭</div>
                </div>
            </div>
        </div>

        <div id="pane-2" class="pane-form layui-form layui-hide" action="">
            <div class="section">
                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">维修类工单配置
                                </span>
                            </div>
                        </div>
                        <div class="title-right">
                            <button class="layui-btn layui-btn-sm layui-btn-primary"
                                lay-on="on_request_class">编辑</button>
                        </div>
                    </div>
                    <div class="p-4 layui-font-gray layui-font-12">
                        工单属于以下请求类(含子级)时，在完工前须填写服务信息
                    </div>

                    <div class="p-4">
                        <div class="table-stripe">
                            <table class="layui-hide" id="currentId" lay-filter="currentFilter"></table>
                        </div>
                    </div>
                    <script type="text/html" id="currentBar">
                        <a class="layui-font-blue mr-3" lay-event="edit">编辑</a>
                        <a class="layui-font-blue mr-3" lay-event="delete">删除</a>
                    </script>

                </div>

                <div class="solid radius p-4 mb-4 layui-font-black">
                    <div class="title-row">
                        <div class="title-left">
                            <div class="title-info">
                                <div class="title-line"></div>
                                <span class="title-text">工单验收配置</span>
                            </div>
                        </div>
                        <div class="title-right">
                            及时验收分析 <input type="checkbox" name="open" lay-skin="switch" lay-filter="switchTest"
                                title="开|关" />

                        </div>
                    </div>
                    <div class="p-4 layui-font-gray layui-font-12">
                        在此时间验收

                    </div>
                    <div class="p-4">
                        <div class="layui-inline">
                            <label class="layui-form-label">工单完成后：</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入" name="nickname" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>


                        验收完毕
                    </div>
                </div>



            </div>

        </div>
    </div>
</div>
</div>
<script>
    layui.use(['form', 'table', 'tabs', 'miniPage', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tabs = layui.tabs,
            laydate = layui.laydate,
            layer = layui.layer,
            util = layui.util,
            element = layui.element,
            miniPage = layui.miniPage;
        /******************** 事件 start ********************/
        form.render();
        /******************** 事件 end ********************/


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);

            });


            return false;
        });
        //监听提交
        form.on('submit(saveBtn1)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);

            });


            return false;
        });

        // 统一打开配置弹窗的方法
        function openConfigModal(urlPath, title, width = 400) {
            try {
                var content = miniPage.getHrefContent(urlPath);
                if (!content) {
                    throw new Error(`加载页面内容失败: ${urlPath}`);
                }

                layer.open({
                    title: title,
                    type: 1,
                    shade: 0.2,
                    maxmin: false,
                    shadeClose: true,
                    area: [width + 'px', 'auto'],
                    content: content,
                });
            } catch (error) {
                console.error(error);
                layer.msg('打开配置窗口失败，请稍后再试');
            }
        }


        util.on('lay-on', {

            // 相机配置
            'on_camera': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/Camera.html', '相机配置');
            },

            // 显示配置
            'on_order_display': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/OrderDisplay.html', '工单显示配置');
            },

            // 工作组管理配置
            'on_work_group': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/WorkGroup.html', '工作组管理配置');
            },
            // 岗位报单配置
            'on_job_requisition': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/JobRequisition.html', '新增配置');
            },
            // 工作位置配置
            'on_work_position': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/WorkPosition.html', '新增配置');
            },
            // 完工描述配置
            'on_complete_description': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/CompleteDescription.html', '工单显示配置');
            },
            // 视频报单配置
            'on_video_order': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/VideoOrder.html', '视频报单配置');
            },
            // 维修类工单配置
            'on_request_class': function () {
                openConfigModal('page/processSupervision/taskCenterConfig/components/RequestClass.html', '新增配置');
            },


        })



        /******************** 渲染组件 start ********************/

        // 指定开关事件
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关 checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
        });

        form.render('select'); //刷新select选择框渲染
       
        // 初始化选项卡
        tabs.render({
            elem: '#planTabs',
            index: 0// 默认选中
        });

        // planTabs 切换事件
        tabs.on('afterChange(planTabs)', function (data) {
            var tabIndex = data.index;
            // 隐藏所有 pane-form
            $('.pane-form').addClass('layui-hide');

            // 显示当前 tab 对应的 pane-form
            $('#pane-' + tabIndex).removeClass('layui-hide');
        });




        /******************** 渲染组件 end ********************/

        table.render({
            elem: '#jobTableId',
            url: 'api/table.json',
            cols: [[
                { field: 'name', minWidth: 100, title: '工作位置' },
                { title: '操作', minWidth: 180, toolbar: '#currentBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });
        table.render({
            elem: '#currentId',
            url: 'api/table.json',
            cols: [[
                { field: 'name', minWidth: 100, title: '请求类' },
                { title: '操作', minWidth: 180, toolbar: '#currentBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });
        table.render({
            elem: '#currentTableId',
            url: 'api/table.json',
            cols: [[
                { field: 'name', minWidth: 180, title: '岗位' },
                { field: 'businessNames', minWidth: 100, title: '默认工作位置' },
                { field: 'city', minWidth: 80, title: '默认工单来源' },
                { title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log('tool(currentTableFilter)====', obj)
            if (obj.event === 'edit') {
                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确认删除吗', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'detail') {  // 监听详情操作
                miniPage.renderPageCreate(`page/laborOperations/laborJobManager/components/planDetail.html?id=${data.id}`)
            }
        });

        // 开启监听 折叠展开事件
        miniPage.listen()

    });
</script>